import React, { Component } from 'react'
import { connect } from 'react-redux'

class Count extends Component {
    render() {
        const { count, add } = this.props
        console.log(this.props)
        return (
            <div>
                CountCount  ---  { count }
                <button onClick = { () => {
                    add(50)
                }}>++</button>
            </div>
        )
    }
    componentDidMount() {
        this.props.getList()
    }
}

// 映射redux中的State去props

let mapStateToPorps = (state) => {
    const { count, data } = state
    return {
        count,
        data
    }
}

// 映射修改redux中数据的方法去props
let mapDispatchToProps = (dispatch) => {
    return {
       add(count) {
         dispatch({ type: "ADD_COUNT", count })
       },
       getList() {
         dispatch({ type: "SET_DATA" })
       }
    }
}

// 柯里化
export default connect(mapStateToPorps, mapDispatchToProps)(Count)
